﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;

namespace FelMaster
{
    public class HealableUnit
    {
        private WoWUnit unit;

        public HealableUnit(WoWUnit Unit)
        {
            unit = Unit;
        }

        public int TimeToLive(double deltaSeconds)
        {
            var oracle = UnitOracle.FindUnit(unit);
            if (oracle == null)
            {
                UnitOracle.WatchUnit(unit, UnitOracle.Watch.HealthVariance);
                return 999999;
            }
            else
                return oracle.TimeToDie(deltaSeconds);
        }

        public int Health { get { return unit.Dead ? 0 : (int)unit.CurrentHealth; } }
        public int MaxHealth { get { return (int)unit.MaxHealth; } }

        public int MissingHealth { get { return MaxHealth - Health; } }

        public bool Tank { get { return tanks.Any(x => x.Guid == unit.Guid); } }
        public bool Healer { get { return healers.Any(x => x.Guid == unit.Guid); } }
        public bool IsMe { get { return unit.IsMe; } }

        public WoWUnit ToUnit() { return unit; }

        protected static List<WoWUnit> tanks = new List<WoWUnit>();
        private static List<WoWUnit> healers = new List<WoWUnit>();
        public static void Pulse()
        {
            //find raid tanks, healers, etc.
            tanks = new List<WoWUnit>();
            healers = new List<WoWUnit>();
            var units = new List<WoWPartyMember>();

            if (ObjectManager.Me.IsInRaid)
                units = ObjectManager.Me.RaidMemberInfos;
            else if (ObjectManager.Me.IsInParty)
                units = ObjectManager.Me.PartyMemberInfos;

            foreach (var u in units)
            {
                var role = u.Role;
                if (role == WoWPartyMember.GroupRole.Tank)
                    tanks.Add(u.ToPlayer().ToUnit());
                else if (role == WoWPartyMember.GroupRole.Healer)
                    healers.Add(u.ToPlayer().ToUnit());
            }
        }
    }
}
